package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.SoulQuestion;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.SoulQuestionMapper;
import com.itheima.service.db.SoulQuestionService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class SoulQuestionServiceImpl implements SoulQuestionService {

    @Autowired
    private SoulQuestionMapper soulQuestionMapper;

    //根据问卷id查找所有问题
    @Override
    public List<SoulQuestion> findByQuestionnaireId(Long id) {
        QueryWrapper<SoulQuestion> wrapper = new QueryWrapper<>();
        wrapper.eq("questionnaire_id", id);
        List<SoulQuestion> soulQuestionList = soulQuestionMapper.selectList(wrapper);
        return soulQuestionList;
    }

    //根据问题id查找
    @Override
    public SoulQuestion findByQuestionId(Long questionId) {
        SoulQuestion soulQuestion = soulQuestionMapper.selectById(questionId);
        return soulQuestion;
    }

    //显示所有问题
    @Override
    public List<SoulQuestion> findQuestionList() {
        List<SoulQuestion> soulQuestionList = soulQuestionMapper.selectList(new QueryWrapper<>());
        return soulQuestionList;
    }



    /*
     *
     *
     * @param pageNum 当前页
     * @param pageSize 页条数
     * @author
     * @date
     * @return com.itheima.domain.vo.PageBeanVo
     */

    @Override
    public PageBeanVo SoulQuestionByPage(Integer pageNum, Integer pageSize) {
        IPage page=new Page(pageNum,pageSize);
        page = soulQuestionMapper.selectPage(page, null);


        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    //问题列表添加
    @Override
    public Integer saveQuestions(SoulQuestion soulQuestion) {
        return soulQuestionMapper.insert(soulQuestion);
    }

    //问题列表修改
    @Override
    public Integer updateSoulQuestions(SoulQuestion soulQuestion) {
        return  soulQuestionMapper.updateById(soulQuestion);
    }

    //问题列表删除
    @Override
    public Integer deleteQuestions(SoulQuestion soulQuestion) {

        return  soulQuestionMapper.deleteById(soulQuestion);
    }


}
